package com.cn.kabalifemerchants.ui.user.activity;


import com.cn.kabalifemerchants.api.Api;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.callback.CacheCallBack;
import com.cn.kabalifemerchants.config.Constants;
import com.cn.kabalifemerchants.ui.login.bean.MsgBean;
import com.cn.kabalifemerchants.ui.user.bean.CashListBean;
import com.cn.kabalifemerchants.ui.user.bean.MyUserInfoBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/18.
 * function:
 */
public class IMoneyTiXianPresenter extends BasePresenter<IMoneyTiXianView> {
    public void onUserInfoData(String token) {
        OkGo.<MyUserInfoBean>get(Api.API_USER_INFO)
                .headers("token", token)
                .execute(new CacheCallBack<MyUserInfoBean>() {
                    @Override
                    public void onSuccess(Response<MyUserInfoBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("我的" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onUserInfoSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onTiXianData(String token, int cash_type, String money, String card, String name, String card_type, String content) {
        OkGo.<MsgBean>post(Api.API_USER_CASH)
                .headers("token", token)
                .params("cash_type", cash_type)
                .params("money", money)
                .params("card", card)
                .params("name", name)
                .params("card_type", card_type)
                .params("content", content)
                .params("app_type", 2)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("我的" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onTiXianSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }


    public void onReleaseListData(String token, int page, int limit) {
        OkGo.<CashListBean>get(Api.API_USER_CASH_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("app_type", 2)
                .execute(new CacheCallBack<CashListBean>() {
                    @Override
                    public void onSuccess(Response<CashListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onCashListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

}
